package com.pi.cs.service;

import java.util.List;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;

import com.pi.base.enumerate.record.RecordState;
import com.pi.comm.sequence.SnowflakeFactory;
import com.pi.cs.dao.entity.CsUserFeedbackEntity;
import com.pi.cs.dao.mapper.CsUserFeedbackMapper;
import com.pi.cs.dao.param.CsUserFeedbackParam;
import com.pi.cs.enumerate.ContactWay;
import com.pi.cs.enumerate.FeedStatus;
import com.pi.cs.facade.FeedBackFacade;
import com.pi.cs.model.FeedBackPostForm;
import com.pi.cs.model.vo.SmartBedFeedBackVo;

@Validated
@Service
public class FeedBackService {
  @Autowired
  private FeedBackFacade feedBackFacade;
  @Autowired
  private CsUserFeedbackMapper feedbackMapper;
  public void addFeedBack(@Valid FeedBackPostForm form) {
    CsUserFeedbackEntity entity = new CsUserFeedbackEntity();
    entity.setContactContent(form.getContact());
    entity.setContactWay(ContactWay.EMAIL.getType());
    entity.setRequestUser(form.getRequestUser());
    entity.setFeedState(RecordState.STATE_NORMAL.getCode());
    entity.setStatus(FeedStatus.UNRESOLVED.getStatus());
    entity.setUserAdvice(form.getUserAdvice());
    entity.setPics(form.getPics());
    entity.setType(form.getType());
    entity.setId(SnowflakeFactory.getDefaultWorker().nextId());
    feedbackMapper.insert(entity);
  }
  
  public List<CsUserFeedbackEntity> queryUserFeed(
      @NotNull(message = "UC_USER.USER_ID_EMPTY") Long userId){
    CsUserFeedbackParam param = new CsUserFeedbackParam();
    param.setRequestUser(userId);
    param.setOrderParam("update_date");
    param.setOrderOperator("DESC");
    return feedbackMapper.findList(param);
  }
  
  public List<SmartBedFeedBackVo> queryUserFeedVO(
      @NotNull(message = "UC_USER.USER_ID_EMPTY") Long userId){
    return feedBackFacade.transFeedBackIntoSmartBedFormat(queryUserFeed(userId));
  }
}
